package data;

import android.app.Activity;
import android.app.Application;

/**
 * Holds any data that must be accessible throughout the application, like the
 * account of the user who is logged in.
 * 
 * @author Kelsey
 */
public class Session extends Application {

	/** name of the account that is logged in. null if not logged in */
	private String accountName = null;

	/** what status of items to filter */
	private String filterStatus = "open";

	/** true to show keepsakes in item list */
	private boolean filterKeepsakeCategory = true;

	/** true to show heirlooms in item list */
	private boolean filterHeirloomCategory = true;

	/** true to show misc items in item list */
	private boolean filterMiscCategory = true;

	/** true to show newest items first */
	private boolean filterNewestDate = true;

	/** show items with this name first **/
	private String searchQuery = "";

	/**
	 * Get an instance of the user's account
	 * 
	 * @param activity
	 *            the current activity
	 * @return an account representing the user
	 */
	public Account getAccount(Activity activity) {
		Account account = new Account();
		try {
			GetAccount getAccount = new GetAccount(activity, getAccountName());
			account = getAccount.getResult();
			if (account == null) {
				account = new Account();
				System.out
						.println("LoginActivity: advance: error. account is null");
			}
		} catch (DBInterfaceError e) {
			e.printStackTrace();
		}

		return account;
	}

	/**
	 * sets the accountName
	 * 
	 * @param name
	 *            the name of the logged in account
	 */
	public void setAccountName(String name) {
		this.accountName = name;
	}

	/**
	 * returns name of logged in account
	 * 
	 * @return the name of the logged in account. null if no account is logged
	 *         in
	 */
	public String getAccountName() {
		return this.accountName;
	}

	/**
	 * sets the filterStatus
	 * 
	 * @param status
	 *            the status of the items
	 */
	public void setFilterStatus(String status) {
		this.filterStatus = status;
	}

	/**
	 * returns status of the items in lists
	 * 
	 * @return the status of items in lists
	 */
	public String getFilterStatus() {
		return this.filterStatus;
	}

	/**
	 * sets the filterKeepsakeCategory
	 * 
	 * @param true to show keepsakes in item list
	 */
	public void setFilterKeepsakeCategory(boolean keepsake) {
		this.filterKeepsakeCategory = keepsake;
	}

	/**
	 * returns if keepsakes should be displayed in item list
	 * 
	 * @return if keepsakes should be displayed in item list
	 */
	public boolean getFilterKeepsakeCategory() {
		return this.filterKeepsakeCategory;
	}

	/**
	 * sets the filterHeirloomCategory
	 * 
	 * @param true to show heirlooms in item list
	 */
	public void setFilterHeirloomCategory(boolean heirloom) {
		this.filterHeirloomCategory = heirloom;
	}

	/**
	 * returns if heirlooms should be displayed in item list
	 * 
	 * @return if heirlooms should be displayed in item list
	 */
	public boolean getFilterHeirloomCategory() {
		return this.filterHeirloomCategory;
	}

	/**
	 * sets the filterMiscCategory
	 * 
	 * @param true to show misc items in item list
	 */
	public void setFilterMiscCategory(boolean misc) {
		this.filterMiscCategory = misc;
	}

	/**
	 * returns if misc items should be displayed in item list
	 * 
	 * @return if misc items should be displayed in item list
	 */
	public boolean getFilterMiscCategory() {
		return this.filterMiscCategory;
	}

	/**
	 * sets the filterNewestDate
	 * 
	 * @param true to show newest items first
	 */
	public void setFilterNewestDate(boolean newest) {
		this.filterNewestDate = newest;
	}

	/**
	 * returns if newest items are shown first
	 * 
	 * @return if newest items are shown first
	 */
	public boolean getFilterNewestDate() {
		return this.filterNewestDate;
	}

	/**
	 * sets the search query;
	 * 
	 * @param query
	 *            - the query to be searched by
	 */
	public void setSearchQuery(String query) {
		System.out.println(query + "@@@@");
		this.searchQuery = query;
	}

	/**
	 * Returns the string being searched for
	 * 
	 * @return the string being searched for
	 */
	public String getSearchQuery() {
		return searchQuery;
	}

}